package com.fq.myapplication.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


//import com.bumptech.glide.Glide;
import com.fq.myapplication.R;
import com.fq.myapplication.activity.LoginActivity;
import android.view.animation.AnimationUtils;
import com.google.android.material.bottomsheet.BottomSheetDialog;


public class ProfileFragment extends Fragment {

    public static ProfileFragment newInstance() {
        ProfileFragment profileFragment = new ProfileFragment();
        return profileFragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);

//        ImageView imageView = view.findViewById(R.id.avatar);

//        Glide.with(this)
//                .load("https://miaobi-lite.bj.bcebos.com/miaobi/5mao/b%276Jyh56yU5bCP5paw5oOF5L6j5aS05YOPXzE3Mjg5NDgyODguMjQ1MjcyMg%3D%3D%27/0.png")
//                .into(imageView);
//        imageView.setImageResource(R.drawable.profile_resized);
        // 登录按钮
//        Button loginButton = view.findViewById(R.id.loginBtn);
//        loginButton.setOnClickListener(v -> {
//            // 跳转到 LoginActivity
//            Intent intent = new Intent(getActivity(), LoginActivity.class);
//            startActivity(intent);
//        });
//         绑定按钮并设置点击监听器
        TextView btnLogin = view.findViewById(R.id.btn_login);
        btnLogin.setOnClickListener(v -> navigateToLogin());

        // 绑定分享锋趣的LinearLayout
        LinearLayout layoutCheckIn = view.findViewById(R.id.btn_check_in);
        if (layoutCheckIn != null) {
            layoutCheckIn.setOnClickListener(v -> {
                BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(requireContext());
                View bottomSheetView = LayoutInflater.from(requireContext())
                        .inflate(R.layout.fragment_dialog_share, null);
                bottomSheetDialog.setContentView(bottomSheetView);

                // 绑定弹窗内的取消按钮
                Button btnCancel = bottomSheetView.findViewById(R.id.btn_cancel);
                btnCancel.setOnClickListener(v2 -> {
                    Animation slideDown = AnimationUtils.loadAnimation(requireContext(), R.anim.slide_down);
                    slideDown.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationEnd(Animation animation) {
                            bottomSheetDialog.dismiss();
                        }
                        @Override public void onAnimationStart(Animation animation) {}
                        @Override public void onAnimationRepeat(Animation animation) {}
                    });
                    bottomSheetView.startAnimation(slideDown);
                });

                bottomSheetDialog.show();
            });
        }
        return view;
    }
    // 跳转
    public void navigateToLogin() {
        Activity activity = getActivity();
        if (activity != null) { // 防止Fragment未附加到Activity时崩溃
            Intent intent = new Intent(activity, LoginActivity.class);
            startActivity(intent);
            //            添加跳转动画
            activity.overridePendingTransition(R.anim.slide_in_bottom,R.anim.slide_out_top);
        }
    }

}